home *** CD-ROM | disk | FTP | other *** search
/ Merciful 5 / Merciful - Disc 5.iso / software / p / personalpaint7.lha / PPaint / Rexx / LightTool.pprx < prev    next >
Encoding:
Text File  |  1997-04-19  |  3.0 KB  |  145 lines

  1. /* Personal Paint Amiga Rexx script - Copyright © 1997 Cloanto Italia srl */
  2.  
  3. /* $VER: LightTool.pprx 1.0 */
  4.  
  5. /** ENG
  6.  This tool lightens (left mouse button) or darkens
  7.  (right mouse button) the image area it is used on.
  8.  
  9.  The tool uses the current brush. The predefined
  10.  one-pixel brush is ideal for use on single pixels.
  11.  Different "oil painting" effects can be achieved
  12.  with brushes in different sizes and shapes.
  13. */
  14.  
  15. IF ARG(1, EXISTS) THEN
  16.     PARSE ARG PPPORT button x0 y0 .
  17. ELSE
  18.     EXIT 0  /* macro execution only */
  19.  
  20. ADDRESS VALUE PPPORT
  21. OPTIONS RESULTS
  22. OPTIONS FAILAT 10000
  23.  
  24. Version 'REXX'
  25. IF RESULT < 7 THEN DO
  26.     Get 'LANG'
  27.     IF RESULT = 1 THEN        /* Deutsch */
  28.         txt_err_oldclient = 'Für dieses Skript_ist eine neuere Version_von Personal Paint erforderlich'
  29.     ELSE IF RESULT = 2 THEN        /* Italiano */
  30.         txt_err_oldclient = 'Questa procedura richiede_una versione più recente_di Personal Paint'
  31.     ELSE                /* English */
  32.         txt_err_oldclient = 'This script requires a newer_version of Personal Paint'
  33.  
  34.     RequestNotify 'PROMPT "'txt_err_oldclient'"'
  35.     EXIT 10
  36. END
  37.  
  38. prev_xp = x0
  39. prev_yp = y0
  40. drawn = 0
  41. GetPaintMode
  42. svpmode = RESULT
  43. GetPen 'FOREGROUND'
  44. svfpen = RESULT
  45. SetPaintMode 'COLOR'
  46. Get 'COLORS'
  47. cnum = RESULT
  48. light. = ''
  49. dark. = ''
  50.  
  51. DO FOREVER
  52.     GetMousePosition
  53.     PARSE VAR RESULT xp yp .
  54.  
  55.     IF xp ~= prev_xp | yp ~= prev_yp | ~drawn THEN DO
  56.         IF ~drawn THEN DO
  57.             xp = x0
  58.             yp = y0
  59.         END
  60.         GetPixel xp yp
  61.         pxcol = RESULT
  62.         GetColors 'FROM' pxcol 'TO' pxcol 'HSV'
  63.         PARSE VAR RESULT hue sat val .
  64.         excl = pxcol
  65.         exnum = 1
  66.         newpxcol = -1
  67.         IF button = 1 THEN DO
  68.             IF light.pxcol = '' THEN DO
  69.                 IF val < 100 THEN DO
  70.                     val = val + 1
  71.                     DO FOREVER
  72.                         FindColor 'COLOR "'hue sat val'" HSV EXCLUDE "'excl'"'
  73.                         col = RESULT
  74.                         GetColors 'FROM' col 'TO' col 'HSV'
  75.                         PARSE VAR RESULT hue2 sat2 val2 .
  76.                         dhue = DeltaHue(hue, hue2)
  77.                         IF val2 > val & dhue < 20 THEN DO
  78.                             newpxcol = col
  79.                             LEAVE
  80.                         END
  81.                         excl = excl col
  82.                         exnum = exnum + 1
  83.                         IF exnum = cnum THEN
  84.                             LEAVE
  85.                     END
  86.                 END
  87.                 light.pxcol = newpxcol
  88.             END
  89.             ELSE newpxcol = light.pxcol
  90.         END
  91.         ELSE DO
  92.             IF dark.pxcol = '' THEN DO
  93.                 IF val > 0 THEN DO
  94.                     val = val - 1
  95.                     DO FOREVER
  96.                         FindColor 'COLOR "'hue sat val'" HSV EXCLUDE "'excl'"'
  97.                         col = RESULT
  98.                         GetColors 'FROM' col 'TO' col 'HSV'
  99.                         PARSE VAR RESULT hue2 sat2 val2 .
  100.                         dhue = DeltaHue(hue, hue2)
  101.                         IF val2 < val & dhue < 20 THEN DO
  102.                             newpxcol = col
  103.                             LEAVE
  104.                         END
  105.                         excl = excl col
  106.                         exnum = exnum + 1
  107.                         IF exnum = cnum THEN
  108.                             LEAVE
  109.                     END
  110.                 END
  111.                 dark.pxcol = newpxcol
  112.             END
  113.             ELSE newpxcol = dark.pxcol
  114.         END
  115.         IF newpxcol >= 0 THEN DO
  116.             SetPen 'FOREGROUND' newpxcol
  117.             PutBrush xp yp
  118.         END
  119.         prev_xp = xp
  120.         prev_yp = yp
  121.         drawn = 1
  122.     END
  123.     ELSE WaitForEvent
  124.  
  125.     GetMouseButton
  126.     IF RESULT ~= button THEN
  127.         LEAVE
  128. END
  129.  
  130. SetPen 'FOREGROUND' svfpen
  131. SetPaintMode svpmode
  132.  
  133. EXIT
  134.  
  135.  
  136.  
  137. DeltaHue: PROCEDURE
  138.  
  139.     h1 = ARG(1)
  140.     h2 = ARG(2)
  141.     d1 = ABS(h1-h2)
  142.     d2 = 360 - MAX(h1,h2) + MIN(h1,h2)
  143.  
  144.     RETURN MIN(d1,d2)
  145.